import { observable, action, autorun, toJS } from 'mobx';
import * as  Apis from '../apis/govern';
import {message} from 'antd';
import { ListStore } from './listStore';
import {WeaLocaleProvider} from 'ecCom'
const getLabel = WeaLocaleProvider.getLabel;

export  class GovernReportStore extends ListStore {
    @observable tasklabels = {};
    @observable condition = [];
    @observable status = {
        loading: false,
        item_three:false,//日期组件展开的样式标志
        value: [],
        datas: [
          {name:getLabel('126831',"全部"),value:'0'},
          {name:getLabel('15537',"今天"),value:'1'},
          {name:getLabel('15539',"本周") ,value:'2'},
          {name:getLabel('126758',"本月"),value:'3'},
          {name:getLabel('383465',"本季"),value:'4'},
          {name:getLabel('15384',"本年"),value:'5'},
          {name:getLabel('27347',"上个月"),value:'7'},
          {name:getLabel('81716',"上一年"),value:'8'},
          {name:getLabel('32530',"指定日期范围"),value:'6'}
        ]
    }
    @observable id;
    @observable type;
    @observable reportType;
    @observable logCondition = [];
    @observable logSearchData = {};
    @observable reporter = "";//浏览按钮值
    @observable reportDate = {"reportDate_end":'',"reportDate_select":'',"reportDate_start":''};//日期组件值
    @observable isdoSearch = false;//是否执行了搜索操作

    @observable taskOptions =[];
    @observable selectvalue ='';

    @observable replaceDatas = [];
    // @action
    // getCondition(params = {}) {
    //     this.id = params.id;
    //     this.type = params.type;
    //     this.status.loading = true;
    //     Apis.getReportCondition(params).then(data => {
    //         this.setCondition(data);
    //         this.status.loading = false;
    //     });
    // }
    //构造新的condition
    // setCondition(dbFormData){
    //     if(_.has(dbFormData,'searchCondition')){
    //         dbFormData.searchCondition = dbFormData.searchCondition || [];
    //         dbFormData.searchCondition.map((c)=>{
    //             let getData = [];
    //             if(_.has(c,'items')){
    //                 let remarkIndex = 0;
    //                 c.items = c.items || [];
    //                 c.items.map((item,index)=>{
    //                     item={
    //                         ...item,
    //                         colSpan: 1,
    //                         labelcol: 8,
    //                         fieldcol: 16
    //                     };
    //                     getData.push(item);
    //                 });
    //                 c.items = [];
    //                 c.items = c.items.concat(getData);
    //             }
    //         });
    //         this.condition = dbFormData.searchCondition;
    //         this.formMyAttent && !this.formMyAttent.isFormInit && this.formMyAttent.initFormFields(dbFormData.searchCondition);
    //     }
    // }

    @action
    getDataList = (params = {}) => {
      //alert(1234321)
        this.id = params.id;
        this.type = params.type;
        this.status.loading = true;
        this.reportType = params.reportType;
        this.selectvalue = '';
        
        this.reporter = "";//浏览按钮值
        this.status.value = [];
        this.replaceDatas = [];
        Apis.getReportList({ id: this.id, type: this.type, reportType: this.reportType }).then(data => {
          if(parseInt(data.status) == 1){
            this.tableStoreMyAttent.getDatas(data.sessionkey, 1);
            if(data.taskSelect){
              this.taskOptions = data.taskSelect.options;
            }
          }else{
            message.error(data.error);
          }
          this.status.loading = false;
        }).catch(error => {
            message.error(error);
        })
    }

    @action
    doSearch = () => {
        //{ id: this.id, type: this.type, ...this.formMyAttent.getFormParams() }
        this.isdoSearch = true;
        Apis.getReportList({ id: this.id, type: this.type, reportType: this.reportType, ...this.reportDate,...{"reporter":this.reporter},selectvalue:this.selectvalue }).then(data => {
            if(parseInt(data.status) == 1){
              this.tableStoreMyAttent.getDatas(data.sessionkey, 1);
            }else{
              message.error(data.error);
            }
            this.status.loading = false;
        }).catch(error => {
            message.error(error);
        });
    }

    /**
     * 获取搜索条件
     */
    @action
    getLogConditons(params = {}) {
        this.id = params.id;
        this.status.loading = true;
        Apis.getLogConditons(params).then(data => {
            if(parseInt(data.status) == 1){
              this.logCondition = data.conditons;
            }else{
              message.error(data.error);
            }
            this.status.loading = false;
        }).catch(error => {
            message.error(error);
        });
    }

    /**
     * 获取列表
     */
    @action
    getLogList(params = {}) {
        this.id = params.id;
        this.status.loading = true;
        Apis.getLogList(params).then(data => {
            if(parseInt(data.status) == 1){
              this.tableStoreMyAttent.getDatas(data.sessionkey, 1);
            }else{
              message.error(data.error);
            }
            this.status.loading = false;
        }).catch(error => {
            message.error(error);
        });
    }

    /**
     * 搜索
     */
    @action
    searchLog(params = {}) {
        if(params){
            this.logSearchData = params;
        }else{
            params = this.logSearchData;
        }
        if(params.date_select == "6" && (!params.date_start || !params.date_end))
            return;
        this.status.loading = true;
        Apis.getLogList({id: this.id,...params}).then(data => {
            if(parseInt(data.status) == 1){
              this.tableStoreMyAttent.getDatas(data.sessionkey, 1);
            }else{
              message.error(data.error);
            }
            this.status.loading = false;
        }).catch(error => {
            message.error(error);
        });
    }


    /**
     * 设置日期组件展开样式
     */
    @action
    setItem_three(boolValue){
        this.status.item_three = boolValue;
    }
    /*
     *数据变化回调
    */
   dateGroupHandle(v){
        this.status.value = v;
        this.reportDate = {"reportDate_end":v[2],"reportDate_select":v[0],"reportDate_start":v[1]};
   }
   /*
   *获取浏览按钮数据
   */
  browserHandle(ids,datas){
    this.reporter = ids;
    this.replaceDatas = datas;
  }
  /*
  *组件卸载清除数据
  */
  clearData = () => {
    this.isdoSearch = false;
  }
  @action
  setSelectValue = (value) =>{
    this.selectvalue = value;
  }
}
